#include "t_box_stream.h"

class T_Box_StreamPrivate
{
public:
    Q_DECLARE_PUBLIC(T_Box_Stream)
    class T_Box_Stream *q_ptr;
    T_Box_Core *m_core;
    T_Box_Control m_control;
    T_Box_Media *m_audio;
    T_Box_Media *m_video;
    qint64 m_max_packet_timing;
public:
    explicit T_Box_StreamPrivate(T_Box_Stream *me, T_Box_Core *a_core)
        : q_ptr(me)
        , m_core(a_core)
        , m_control(a_core, me)
        , m_audio(0)
        , m_video(0)
        , m_max_packet_timing(0)
    {
        Q_ASSERT(m_control.isValid());
    }
    ~T_Box_StreamPrivate()
    {
        if(m_audio) delete m_audio;
        if(m_video) delete m_video;
    }
};

T_Box_Stream::T_Box_Stream(T_Box_Core *a_core)
{
    d_ptr = new T_Box_StreamPrivate(this, a_core);
}

T_Box_Stream::~T_Box_Stream()
{
    this->finish();
}

T_Box_Core *T_Box_Stream::core()
{
    Q_D(T_Box_Stream);
    return d->m_core;
}

bool T_Box_Stream::openAudio()
{
    Q_D(T_Box_Stream);
    if(!d->m_audio) d->m_audio = d->m_control.openMedia(CODEC_TYPE_AUDIO);
    return !!d->m_audio;
}

bool T_Box_Stream::openVideo()
{
    Q_D(T_Box_Stream);
    if(!d->m_video) d->m_video = d->m_control.openMedia(CODEC_TYPE_VIDEO);
    return !!d->m_video;
}

T_AV_Packet *T_Box_Stream::readPacket()
{
    Q_D(T_Box_Stream);
    return d->m_control.readPacket();
}

void T_Box_Stream::run()
{
}
